package com.chenfan.process.entity.po;

import java.util.Date;

import com.baomidou.mybatisplus.annotation.TableName;
import com.chenfan.ccp.util.tool.UuidUtil;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author liuming
 * @date 2021/10/19 审批实例快照
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "process_instance_snapshot")
public class ApprovalSnapshotPo {

    @ApiModelProperty("主键ID")
    private Long id;

    @ApiModelProperty("审批实例ID")
    private Long approvalId;

    @ApiModelProperty("关联关系, JSON字符串")
    private String relation;

    @ApiModelProperty("快照关系")
    private String approvalTemplateSnapshot;

    @ApiModelProperty("创建时间")
    private Date createDate;

    @ApiModelProperty("更新时间")
    private Date updateDate;

    @Data
    public static class Constants {
        private Constants() {}

        public static final String APPROVAL_ID = "approval_id";
    }

    public static ApprovalSnapshotPo ofDefault(Long approvalId) {
        ApprovalSnapshotPo approvalSnapshotPo = new ApprovalSnapshotPo();
        approvalSnapshotPo.setId(UuidUtil.generateId());
        approvalSnapshotPo.setApprovalId(approvalId);
        approvalSnapshotPo.setCreateDate(new Date());
        return approvalSnapshotPo;
    }

    public void updateSelf() {
        setUpdateDate(new Date());
    }
}
